<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Settings extends Controller_Main {
    
    public function before(){
        parent::before();
    }
    
    public function after(){
//        $this->scripts[]='media/js/settings.js';
        parent::after();
    }
    
    public function action_index(){
        $this->template->title .= ' - Ustawienia';
        $this->template->content = View::factory('settings/index');
        $id = $this->request->param('id');
        
        $data = array();
        
        $submit = Request::g('submit');
        Model_Settings::init();
        
        if($submit){
            foreach($_POST as $k=>$val){
                if(substr($k, 0, 9)=='settings-'){
                    $settingsKey = str_replace('settings-', '', $k);
                    Model_Settings::setVal($settingsKey, $val);
                }
            }
            Model_Settings::saveValues();
            Model_Settings::reinit();
        }
        $settingsVals = Model_Settings::getAllVals();
        
        foreach($settingsVals as $k=>$val){
            $data['settings-'.$k]=$val;
        }
        
        $this->template->content->data = $data;
    }

} 